<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>发布微博页面</h1>
<form action="">
  <input type="text" name="title" placeholder="请输入微博标题">
  <input type="text" name="content" placeholder="请输入微博正文">
  <input type="file" name="picFile">
  <input type="button" value="发布微博" @click="send()">
</form>
<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
  let v = new Vue({
    el:"form",
    data:{},
    methods:{
      send:function () {
        let data = new FormData(document.querySelector("form"));
        if(data.get("picFile").name==""){
            alert("请选择上传的图片");
            return;
        }
        axios.post("/weibo/insert",data).then(function (response) {
          if(response.data==1){
            alert("上传完成");
            location.href = "/";
          }else{
            alert("请先登录!");
            location.href = "/login.html";
          }
        })
      }
    }
  })
</script>
</body>
</html>